#ifndef AQUARIUM_DEVICE_H
#define AQUARIUM_DEVICE_H

#include <avr/pgmspace.h>
#include "Arduino.h"

#include <LiquidCrystal.h>
#include <EEPROM.h>

#include "utility.h";
#include "Clock.h";
#include "Aquarium_Modes.h";
#include "Temp.h";

const byte DEVICE_MODE_NUMBER     = 3;
const byte DEVICE_MODE_OFF     = 0;
const byte DEVICE_MODE_ON       = 1;
const byte DEVICE_MODE_AUTO  = 2;

const byte DEVICE_PRINT_START_INDEX_MODE     = 0;
const byte DEVICE_PRINT_END_INDEX_MODE     = 0;
const byte DEVICE_PRINT_START_INDEX_MODES   = DEVICE_PRINT_END_INDEX_MODE + 1;
const byte DEVICE_PRINT_END_INDEX_MODES        = DEVICE_PRINT_START_INDEX_MODES +  NUMBER_OF_MODES - 1;

const byte DEVICE_NUMBER_OF_TIMERS     = 3;  
const byte DEVICE_PRINT_TIMERS_LEN     = 3;  
const byte DEVICE_PRINT_START_INDEX_TIMER   = DEVICE_PRINT_END_INDEX_MODES + 1;
const byte DEVICE_PRINT_END_INDEX_TIMER        = DEVICE_PRINT_START_INDEX_TIMER + (DEVICE_NUMBER_OF_TIMERS*DEVICE_PRINT_TIMERS_LEN) - 1;

const byte DEVICE_TEMP_MODE_NUMBER         = 3;
const byte DEVICE_TEMP_MODE_OFF                 = 0;
const byte DEVICE_TEMP_MODE_TURN_OFF    = 1;
const byte DEVICE_TEMP_MODE_TURN_ON       = 2;
const byte DEVICE_PRINT_TEMP_LEN     = 6;  
const byte DEVICE_PRINT_START_INDEX_TEMP   = DEVICE_PRINT_END_INDEX_TIMER + 1;
const byte DEVICE_PRINT_END_INDEX_TEMP        = DEVICE_PRINT_START_INDEX_TEMP + (TEMP_NUMBER_OF_PROBES*DEVICE_PRINT_TEMP_LEN) - 1;

const byte DEVICE_PRINT_NUMBER_OF_LINE = DEVICE_PRINT_END_INDEX_TEMP+1;

class Aquarium_Device
{
public:
  Aquarium_Device() : Temp_switch(0) {
  };

  void init(byte _DeviceNum,int _PinNum );
  void Save_To_EEPROM();
  void update();

  void Key_Prass(byte index,char Key);
  void Print(byte index);

private:
  void Turn_On();     // Tuen the divice on
  void Turn_Off();  // Tuen the divice off

  bool Check_Aquarium_mode(byte Aquarium_mode);  // return true if the device should be on 
  void Set_Aquarium_mode(byte Aquarium_mode , byte val); 
  bool Check_Timer(byte Cur_Hr,byte Cur_Min);  // return true if the device should be turn on
  bool Check_Temp(byte Mode);     // return true if the device should be turn on / turn off


  byte DeviceNum;
  int PinNum;
  
  byte Device_Mode;

  byte Aquarium_modes; // each bit for each mode , bit 0 for mode 0

  bool Timer_On[DEVICE_NUMBER_OF_TIMERS];
  byte Start_Timer_HR[DEVICE_NUMBER_OF_TIMERS];
  byte Start_Timer_MIN[DEVICE_NUMBER_OF_TIMERS];
  byte End_Timer_HR[DEVICE_NUMBER_OF_TIMERS];
  byte End_Timer_MIN[DEVICE_NUMBER_OF_TIMERS];

  bool    Temp_switch;
  byte    Temp_His_byte[TEMP_NUMBER_OF_PROBES];
  float  Temp_His[TEMP_NUMBER_OF_PROBES];
  byte    Temp_High_Mode[TEMP_NUMBER_OF_PROBES];
  byte    Temp_High_h[TEMP_NUMBER_OF_PROBES],Temp_High_l[TEMP_NUMBER_OF_PROBES];
  float Temp_High[TEMP_NUMBER_OF_PROBES];
  byte    Temp_Low_Mode[TEMP_NUMBER_OF_PROBES];
  byte    Temp_Low_h[TEMP_NUMBER_OF_PROBES],Temp_Low_l[TEMP_NUMBER_OF_PROBES];
  float Temp_Low[TEMP_NUMBER_OF_PROBES];

};


#endif



